package com.zhou.system.management.controller;


import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.zhou.common.lib.model.CommonPage;
import com.zhou.common.lib.model.Response;
import com.zhou.system.management.entity.SysRole;
import com.zhou.system.management.model.ao.SysRoleAddAo;
import com.zhou.system.management.model.ao.SysRoleEnableAo;
import com.zhou.system.management.model.ao.SysRoleQueryAo;
import com.zhou.system.management.model.ao.SysRoleUpdateAo;
import com.zhou.system.management.model.vo.SysRoleVo;
import com.zhou.system.management.service.impl.SysRoleServiceImpl;
import com.zhou.system.management.validgroup.BaseGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 角色信息表 前端控制器
 * </p>
 *
 * @author zxf
 * @since 2023-05-18
 */
@Api(tags = "角色模块")
@ApiSupport(order = 1)
@RestController
@RequestMapping("/sys-role")
public class SysRoleController {

    @Autowired
    private SysRoleServiceImpl roleService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "查询角色列表")
    @PostMapping("/query")
    public Response<CommonPage<SysRole>> query(@RequestBody SysRoleQueryAo queryAo) {
        CommonPage<SysRole> result = roleService.query(queryAo);
        return Response.success(result);
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "新增角色")
    @PostMapping("/add")
    public Response add(@Validated @RequestBody SysRoleAddAo addAo) {
        roleService.add(addAo);
        return Response.success();
    }

    @ApiOperationSupport(order = 4, ignoreParameters = "roleKey")
    @ApiOperation(value = "更新角色")
    @PostMapping("/update")
    public Response update(@Validated(BaseGroup.UpdateGroup.class) @RequestBody SysRoleUpdateAo updateAo) {
        updateAo.setRoleKey(null);
        roleService.update(updateAo);
        return Response.success();
    }

    @ApiOperationSupport(order = 4)
    @ApiOperation(value = "删除角色")
    @DeleteMapping("/{roleId}")
    public Response<String> update(@PathVariable Long roleId) {
        roleService.delete(roleId);
        return Response.success();
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "启用角色")
    @PostMapping("/enableRole")
    public Response enableRole(@Validated @RequestBody SysRoleEnableAo ao) {
        roleService.enableRole(ao);
        return Response.success();
    }

    @ApiOperationSupport(order = 8)
    @ApiOperation(value = "启用角色")
    @GetMapping("/query/{roleId}")
    public Response<SysRoleVo> queryOne(@PathVariable Long roleId) {
        SysRoleVo sysRoleVo = roleService.queryOne(roleId);
        return Response.success(sysRoleVo);
    }


}
